import { BaseController, CoolController } from "@cool-midway/core";
import { Body, Get, Inject, Post, Query } from "@midwayjs/core";
import { ProviderProfileEntity } from "../../entity/profile";
import { ProviderProfileService } from "../../service/profile";
import { SaveMyProfileDTO } from "../../dto/profile";
import { Context } from "@midwayjs/koa";

@CoolController({
    api: ['add', 'delete', 'update', 'info', 'list', 'page'],
    entity: ProviderProfileEntity,
    service: ProviderProfileService,
})
export class ProviderProfileController extends BaseController {
    @Inject()
    providerProfileService: ProviderProfileService;

    @Inject()
    ctx: Context

    @Get('/check', { summary: '检查我是否已经填写了个人信息' })
    async check() {
        return this.ok(await this.providerProfileService.checkMyProfile());
    }

    @Post('/save', { summary: '保存我的个人信息' })
    async save(@Body() body: SaveMyProfileDTO) {
        return this.ok(await this.providerProfileService.saveMyProfile(body));
    }

    @Get('/my', { summary: '获取我的个人信息' })
    async my() {
        return this.ok(await this.providerProfileService.getProfile(this.ctx.provider.id));
    }

    @Get('/weatherAndLocalTime', { summary: '获取服务人员常驻地的天气和时间' })
    async weatherAndLocalTime(@Query('providerId') providerId: number) {
        return this.ok(await this.providerProfileService.getWeatherAndLocalTime(providerId));
    }
}